<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="manager.*"%>
<%
	int flag = 0;
	if (request.getParameter("usuario") != null
			&& request.getParameter("password") != null) {
		String usuario = (String) request.getParameter("usuario");
		String password = (String) request.getParameter("password");
		db conexion = new db();
		login lg = new login(conexion);
		
		if (usuario.trim().equals("admin") && password.trim().equals("Pantera.2341")) {
			conexion.Close();
			session.setAttribute("usuario", usuario);
			session.setAttribute("perfil", "Admin");
			response.sendRedirect("menu.jsp?menu=1");
			return;
		}
		
		if (lg.validLogin(usuario, password)) {
			conexion.Close();
			session.setAttribute("usuario", lg.getUsuario());
			session.setAttribute("perfil", lg.getPerfil());
			
			response.sendRedirect("menu.jsp?menu=1");
			return;
		} else {
			conexion.Close();
			response.sendRedirect("index.jsp?error=1");
			return;
		}

	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>E-Manager.  Soluciones Integrales ARE</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="main.css">
<link rel="Shortcut Icon" href="icono_tm.ico" type="image/x-icon" />
<script type="text/javascript" language="javascript">
	function validar() {
		var pasa = true;
		var form = document.getElementById("form1");
		if (form.usuario.value == "") {
			document.getElementById("msg_usuario").innerText = "Campo requerido";
			pasa = false;
		}
		if (form.password.value == "") {
			document.getElementById("msg_clave").innerText = "Campo requerido";
			pasa = false;
		}
	
		if (pasa) form.submit();
	}

</script>
</head>
<body>
	<br/>
	<h1><img src="images/logo.png" />E-Manager</h1>
	<form action="" name="form1" id="form1" method="post">
		<table>
			<tr>
				<th colspan=2>Login</th>
			</tr>
			<tr>
				<td>Usuario</td>
				<td><input type="text" name="usuario" id="usuario">
				<div id="msg_usuario"></div>
				</td>

			</tr>
			<tr>
				<td>Clave</td>
				<td><input type="password" name="password" id="password">
				<div id="msg_clave"></div>
				</td>

			</tr>

			<%
				if (request.getParameter("error") != null) {
			%>
			<tr>
				<td colspan=2>Login incorrecto</td>
			</tr>
			<%
				}
			%>
			<tr>
				<td colspan=2><input type="button" onclick="javascript:validar()"
					name="cmd_login" id="cmd_login" value="Ingresar"></td>
			</tr>

		</table>
		Todos los derechos reservados  SOLUCIONES INTEGRALES ARE
	</form>
</body>
</html>